# 名称:Backdream
# 时间2022/12/27 11:39
# 第一个商品详情界面页面类

from appium.webdriver.common.mobileby import MobileBy as By
from pages.base_page import BasePage
from appium.webdriver.common.touch_action import TouchAction

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

class ProductFirstPage(BasePage):
    """第一个商品的详情页面类"""
    #定位器
    # share_btn_locator = (By.CLASS_NAME, "android.widget.ImageView")
    customer_service_locator = (By.XPATH, "//android.view.View[@text=\"客服\"]")
    back_btn_locator = (By.XPATH, "//android.widget.ImageButton[@resource-id=\"com.gfeng.daydaycook:id/backButton\"]")
    homepage_btn_locator = (By.XPATH, "//android.widget.ImageButton[@resource-id=\"com.gfeng.daydaycook:id/backButton\"]")
    new_shopping_card_locator = (By.XPATH, "//android.view.View[@text=\"购物车\"]")
    share_wechat_locator = (By.XPATH, "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/rv_share\"]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.ImageView[2]")
    share_moments_locator = (By.XPATH, "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/rv_share\"]/android.widget.RelativeLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.ImageView[2]")
    share_microblog_locator = (By.XPATH, "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/rv_share\"]/android.widget.RelativeLayout[3]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.ImageView[2]")
    customer_service_phone_locator = (By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/tv_phone\"]")
    homepage_btn_result_locator = (By.XPATH, "//android.widget.TextView[@text=\"大家都在搜“日日煮星厨菜肴”\"]")
    new_shopping_card_result_locator = (By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/mTitle\"]")
    pop_wetchat_locator = (By.XPATH, '//*[@text="{}"]'.format("请安装微信客户端"))
    pop_microblog_locator = (By.XPATH, '//*[@text="{}"]'.format("请安微博客户端"))



    #方法
    def share_btn_tap(self):
        # self.find_element(self.share_btn_locator).click()
        action = TouchAction(self.driver)
        action.tap(x=853,y=92)
        action.perform()

    def customer_service_click(self):
        self.find_element(self.customer_service_locator).click()

    def back_btn_click(self):
        self.find_element(self.back_btn_locator).click()

    def homepage_btn_click(self):
        self.find_element(self.homepage_btn_locator).click()

    def new_shopping_card_click(self):
        self.find_element(self.new_shopping_card_locator).click()

    def wechat_click(self):
        self.find_element(self.share_wechat_locator).click()

    def moments_click(self):
        self.find_element(self.share_moments_locator).click()

    def microblog_click(self):
        self.find_element(self.share_microblog_locator).click()

    def get_customer_service_phone(self):
        return self.find_element(self.customer_service_phone_locator).text

    def get_homepage_btn_result(self):
        return self.find_element(self.homepage_btn_result_locator).text

    def get_new_shopping_card_result(self):
        return self.find_element(self.new_shopping_card_result_locator).text

    def get_pop_wechat_message(self):
        wait = WebDriverWait(self.driver, 5, 0.5)
        return wait.until(EC.presence_of_element_located(self.pop_wetchat_locator)).text

    def get_pop_microblog_message(self):
        wait = WebDriverWait(self.driver, 5, 0.5)
        return wait.until(EC.presence_of_element_located(self.pop_microblog_locator)).text









